public class testAnimal {
    public static void main(String[] args) {
        Cat cat=new Cat("小琪",6);
        Dog dog=new Dog("小涛",7);
        //向上转型
        Animal animal=cat;
        animal.eat();
        animal=dog;
        animal.eat();
        if(animal instanceof Cat){
            cat=(Cat)animal;
            cat.mow();
        }
        if(animal instanceof Dog){
            dog=(Dog)animal;
            dog.bark();
        }
    }
}
